package com.ysstech.common.controller;


import com.ysstech.common.cache.RedisCacheManager;
import com.ysstech.common.entity.PageBean;
import com.ysstech.common.enums.YssEnum;
import com.ysstech.common.service.DicvalueService;
import com.ysstech.common.service.LoggerService;
import com.ysstech.common.service.SendMailService;
import com.ysstech.common.util.RestTemplateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.sql.DataSource;

@Slf4j
public class BaseController {
    @Autowired
    protected RedisCacheManager redisCacheManager;
    @Autowired
    protected DicvalueService dicValueService;
    @Autowired
    protected SendMailService sendMailService;
    @Autowired
    protected LoggerService loggerService;
    @Autowired
    protected RestTemplateUtil restTemplateUtil;
    @Autowired
    protected DataSource dataSource;


    /**
     * 分页
     *
     * @param page
     * @param rows
     * @return
     */
    public PageBean getPage(String page, String rows) {
        PageBean pageBean = new PageBean(null, 0);
        if (StringUtils.isNotBlank(page) && StringUtils.isNotBlank(rows)) {
            pageBean.setPageNum(Integer.parseInt(page));
            pageBean.setPageSize(Integer.parseInt(rows));
        } else {
            pageBean.setPageNum(Integer.valueOf(YssEnum.YSS_PAGENUM.getCode()));
            pageBean.setPageSize(Integer.valueOf(YssEnum.YSS_PAGESIZE.getCode()));
        }
        return pageBean;
    }

}
